package Widget

import (
	"github.com/lxn/walk"
	"github.com/lxn/walk/declarative"
)

type XListBox struct {
	Sprite   *declarative.ListBox
	listBox  **walk.ListBox
	listBox2 *walk.ListBox //这个用指针的是错误的
	items    []string
}

func (m *XListBox) checkList() bool {
	if m.listBox == nil {
		return false
	}
	if *m.listBox == nil {
		return false
	}
	if m.items == nil {
		return false
	}
	//if *m.items == nil {
	//	return false
	//}
	return true
}
func (m *XListBox) AddBoxText(newItem string) {
	if !m.checkList() {
		return
	}
	m.items = append(m.items, newItem)
	(*m.listBox).SetModel(m.items)
	//m.listBox2.SetModel(*m.items)
}

func (m *XListBox) ClearBoxText() {
	if !m.checkList() {
		return
	}
	m.items = []string{}           // 清空数据模型
	(*m.listBox).SetModel(m.items) // 更新 ListBo
}

func CreateListBox() *XListBox {
	var listBox *walk.ListBox
	b := &XListBox{
		Sprite: &declarative.ListBox{
			AssignTo: &listBox,
			//Model:    Model, //items,
		},
	}
	b.listBox = &listBox
	b.listBox2 = listBox //这是错误的用法
	b.items = []string{}
	return b
}
